package com.offcn.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.offcn.common.JsonController;
import com.offcn.pojo.Clients;
import com.offcn.pojo.Member;
import com.offcn.service.ClientsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("client")
public class ClientsController extends JsonController {

    @Autowired
    ClientsService clientsService;
    /*
        需求:展示客列表
        URL:http://localhost/eastCMS/client/getList?pageIndex=1&pageSize=30
        逻辑：1.接受请求
             2.接受分页数据
             3.权限查询clients
             4.将查询到的数据用json打包

         需求: 展示客户列表
     URL;http://localhost:8080/eastCMS/client/getList?pageIndex=1&pageSize=30
      逻辑：
          1：接收请求
          2：接收数据
          3：（权限）查询 clients
          4：将查询到的数据用json打包


    */
    @RequestMapping("getList")
    public  void  getList(@RequestParam(defaultValue = "1")Integer pageIndex, HttpServletRequest request, HttpServletResponse response){

        Member memberSession = (Member) request.getSession().getAttribute("member");

        PageHelper.startPage(pageIndex,30);

        List<Clients> clientsList=clientsService.getList(memberSession);

        PageInfo<Clients> clientsPageInfo = new PageInfo<>(clientsList);      // 将clientsList数据传给PageInfo

        JsonUtilObjecToJson(response,"200","success",clientsPageInfo);

    }

}
